<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Administrator
 * Date: 25/05/11
 * Time: 14:59
 * To change this template use File | Settings | File Templates.
 */

abstract class Controller
{

    protected $view;


    public function valid_action($action)
    {
        return function_exists($action) ? true : false;
    }

    public function __construct(View $view)
    {
        $this->view = $view;
        $this->init();

    }


    public abstract function index();

    public abstract function toevoegen();

    public abstract function bewerken();

    public abstract function overzicht();

    public abstract function add();

    public abstract function update();

    public abstract function delete();

    public function init()
    {
        foreach (Config::get('init', 'service') as $key => $data) {
            $this->view->assign($key, $data);
        }
        $clearence = -1;
        if (strcmp(strtolower(UrlDecoder::get_Controller_Name()), 'login') != 0) {
            if (!is_bool(Medewerker::authenticate())) {
                $this->view->assign('form_URL', SDS::getURL('login', 'submit', null));
                $this->view->assign('level', '-1');
                $this->view->render('Login.tpl');
                exit;
            }
        }
        if (!is_null(Register::get('medewerker_ID', true)))
            $clearence = Medewerker::read(Register::get('medewerker_ID', true))->getClearence();
        $this->view->assign('logout_link', SDS::getURL('Login', 'logout'));

        $this->view->assign('level', $clearence);
        require_once(Config::acquire("Menu", APPLICATION));

        Menu::create('Incidenten', 1)->add(new MenuItem('Incidenten', SDS::getURL('Incident', null)))
                ->add(new MenuItem('Problemen', SDS::getURL('Probleem', null)))->getItems();
        Menu::create('Onderhoud', 2)->add(new MenuItem('Diensten', SDS::getURL('Diensten', null)))
                ->add(new MenuItem('Hardware', SDS::getURL('Hardware', null)))
                ->add(new MenuItem('Software', SDS::getURL('Software', null)))
                ->add(new MenuItem('Leverancier', SDS::getURL('Leverancier', null)))
                ->add(new MenuItem('Licentie', SDS::getURL('Licentie', null)))
                ->add(new MenuItem('Locatie', SDS::getURL('Locatie', null)))
                ->add(new MenuItem('Netwerk', SDS::getURL('Netwerk', null)));
        Menu::create('Vragenscript', 2)->add(new MenuItem('Probleem', SDS::getURL('Probleem', null)))
                ->add(new MenuItem('Oplossing', SDS::getURL('Oplossing', null)))
                ->add(new MenuItem('Question', SDS::getURL('Question', null)))
                ->add(new MenuItem('Sla', SDS::getURL('Sla', null)))
                ->add(new MenuItem('Workaround', SDS::getURL('Workaround', null)));
        Menu::create('Administratie', 3)->add(new MenuItem('Gebruiker', SDS::getURL('Gebruiker', null)))
                ->add(new MenuItem('Medewerker', SDS::getURL('Employee', null)));


        foreach (Menu::getMenu() as $menu)
            $this->view->assign($menu->getTitle() . '_Menu', $menu->getItems());


        $this->view->assign('sub', Menu::getsub());

    }

    public function setView($view)
    {
        $this->view = $view;
    }

    public function getView()
    {
        return $this->view;
    }

}
